require "rubygems"
require "ai4r"

net = Ai4r::NeuralNetwork::Backpropagation.new([11, 6, 1])


exemples = []

f = File.open("credtrain.txt", "r")

f.each_line do|line|
  a = []
  line.split("\t").each {|x| a << x.to_i}
  exemples << a
end


f.close


teste = []
f = File.open("credtest.txt","r")

f.each_line do |line|
  a = []
  line.split("\t").each {|x| a << x.to_i}


  teste << a
end

f.close




#exemples =[ 
#[1,	0,	360,	0,	313,	9,	52,	0,	25,	48,	0,	1],
#[0,	0,	350,	1,	468,	10,	65,	0,	33,	6,	0,	1],
#[0,	0,	1100,	0,	829,	9,	125,	0,	56,	48,	0,	1],
#[0,	0,	3000,	0,	552,	12,	76,	1,	31,	60,	0,	1],
#[1,	0,	1000,	0,	809,	12,	111,	0,	24,	7,	0,	1],
#[0,	0,	300,	0,	331,	6,	74,	1,	41,	0,	0,	1],
#[0,	2,	580,	1,	349,	10,	51,	0,	30,	6,	0,	0],
#[0,	0,	300,	0,	416,	10,	64,	0,	48,	108,	0,	1],
#[0,	0,	1500,	0,	688,	6,	148,	0,	59,	48,	0,	0]
#]

1500.times do |i|
  net.train(exemples[i][0..10], [exemples[i][11]]) 
end

577.times do |i|
 res = nil
  z = net.eval(exemples[i][0..10]).first.to_f 
  if z > 0.5 
    res = 1
  else 
    res = 0
  end  
  if exemples[i][11] == res
    puts "Acertou - +1 ponto #{exemples[i][11]} - #{z}"
  else
    puts "errou  - -1 ponto #{exemples[i][11]} - #{z}"

  end
end
